home *** CD-ROM | disk | FTP | other *** search
/ Aminet 38 / Aminet 38 (2000)(Schatztruhe)[!][Aug 2000].iso / Aminet / util / misc / MultiRen.lha / MultiRen / Developers / SwapName-Plugin.e < prev    next >
Encoding:
Text File  |  2000-05-03  |  3.8 KB  |  138 lines

  1. /* Swapname-plugin v1.0 by Deniil 715! for MultiRen
  2.    Made 2000-05-02
  3.    E-mail to me, Daniel Westerberg: deniil@algonet.se
  4. */
  5.  
  6. CONST NUMSTRINGS_FOR_THIS_PLUGIN=1, FILE_NAME_LENGTH=512,
  7.       COM_ASK=1, COM_EXTRACT=2, COM_CONFIGURE=3, COM_ABOUT=4, COM_QUIT=5,
  8.       ERR_OK=0,
  9.       ERR_NOMEM=1,
  10.       ERR_NOFILE=2,
  11.       ERR_NOSIG=3,
  12.       ERR_NOTIMPL=4,
  13.       ERR_UNKNOWN=5,
  14.       ERR_OTHER=6,
  15.       ERR_WRONGFORMAT=7,
  16.       ERR_FATAL=20
  17.  
  18. OBJECT multiren_plugin
  19.  id:LONG
  20.  task:LONG
  21.  sig:LONG
  22.  return:INT
  23.  command:CHAR
  24.  numstrings:CHAR
  25.  stringlist[256]:ARRAY OF LONG
  26.  name:PTR TO CHAR
  27. ENDOBJECT
  28.  
  29. DEF mrp:PTR TO multiren_plugin, -> The communication object
  30.     s[FILE_NAME_LENGTH]:STRING, -> The string we will use and return to MultiRen
  31.     fh, inclext=1               -> The configuration..
  32.  
  33. PROC main()
  34.  DEF sel, sigbit, sig, mtask, msig
  35.  '$VER: SwapName v1.0 by Deniil 715! (2000-05-02)'
  36.  IF arg
  37.   IF mrp:=Val(arg)
  38.    IF mrp.id="MRPO"
  39.     IF (sigbit:=AllocSignal(-1))>=0
  40.      sig:=Shl(1,sigbit)
  41.      LOOP
  42.       sel:=mrp.command
  43.       SELECT sel
  44.       CASE COM_ASK
  45.        mtask:=mrp.task
  46.        msig:=mrp.sig
  47.        mrp.return:=ask()
  48.        SetProgramName(mrp.name)
  49.        mrp.task:=FindTask(NIL)
  50.        mrp.sig:=sig
  51.       CASE COM_EXTRACT   ; mrp.return:=extract()
  52.       CASE COM_CONFIGURE ; mrp.return:=config()
  53.       CASE COM_ABOUT     ; mrp.return:=about()
  54.       CASE COM_QUIT
  55.        FreeSignal(sigbit)
  56.        mrp.return:=cleanup()
  57.        Signal(mtask,msig)
  58.        RETURN
  59.       DEFAULT ; mrp.return:=ERR_UNKNOWN
  60.       ENDSELECT
  61.       Signal(mtask,msig)
  62.       Wait(sig)
  63.      ENDLOOP
  64.     ELSE
  65.      Signal(mrp.task,mrp.sig)
  66.      mrp.return:=ERR_NOSIG
  67.      RETURN
  68.     ENDIF
  69.    ENDIF
  70.   ENDIF
  71.  ENDIF
  72.  WriteF('This is a plugin for MultiRen!\n' +
  73.         'It is not supposed to be executed manually!\n' +
  74.         'Use it through the Renplacer tool in MultiRen instead!\n')
  75. ENDPROC ERR_FATAL
  76.  
  77. PROC ask()
  78.  mrp.numstrings:=NUMSTRINGS_FOR_THIS_PLUGIN   -> I will return one string
  79.  mrp.stringlist[0]:='Filename turn backwards' -> Setting information-strings
  80.  mrp.name:='SwapName'                         -> This plugins name
  81.  IF fh:=Open('ENVARC:SwapName-plugin.cfg',OLDFILE) -> Open configfile
  82.   inclext:=Inp(fh) -> The prefs telling if we should include extension
  83.                    -> in the swap or not..
  84.   Close(fh)
  85.  ENDIF
  86. ENDPROC
  87.  
  88. PROC extract() -> Do my stuff..
  89.  DEF x, y, z, st
  90.  st:=FilePart(mrp.name) -> Note that we get the complete path in name
  91.                         -> and must separate it to get the filename.
  92.  x:=StrLen(st)-1
  93.  IF x<FILE_NAME_LENGTH
  94.   IF inclext
  95.    FOR y:=0 TO x DO s[y]:=st[x-y]
  96.    SetStr(s,x+1)
  97.   ELSE
  98.    FOR z:=x TO 0 STEP -1 DO EXIT st[z]="."
  99.    IF z>0 THEN DEC z ELSE z:=x
  100.    FOR y:=0 TO z DO s[y]:=st[z-y]
  101.    SetStr(s,z+1)
  102.    IF z<x THEN StrAdd(s,st+z+1)
  103.   ENDIF
  104.   mrp.stringlist[0]:=s -> Setting the string-list position 0 to point to our string
  105.   RETURN ERR_OK
  106.  ELSE
  107.   RETURN ERR_OTHER -> Filename was longer than the set max-length for MultiRen v1.3
  108.  ENDIF
  109. ENDPROC
  110.  
  111. PROC config()
  112.  inclext:=req('Do you want the extension to be\n' +
  113.               'part of the filename swapping??',
  114.               'Yes|No|Cancel')
  115.  IF inclext
  116.   IF fh:=Open('ENVARC:SwapName-plugin.cfg',NEWFILE)
  117.    Out(fh,inclext AND 1)
  118.    Close(fh)
  119.   ELSE
  120.    req('Could not save the settings!','OK')
  121.   ENDIF
  122.  ENDIF
  123. ENDPROC ERR_OK -> Will always return ERR_OK here so that MultiRen will not
  124.                -> put up another requester telling this operation failed.
  125.  
  126. PROC about()
  127.  IF req('SwapName Plugin v1.0 by Deniil 715! for MultiRen\n\n' +
  128.         'It was made 2000-04-02 in Amiga-E\n\n' +
  129.         'E-mail: deniil@algonet.se','More|OK')
  130.   req('This plugin will swap the filename backwards.\n' +
  131.       'It features a setting to include the file-\n' +
  132.       'extension in the swapping or not.','OK')
  133.  ENDIF
  134. ENDPROC ERR_OK
  135.  
  136. PROC cleanup() IS ERR_OK
  137.  
  138. PROC req(body,gads) IS EasyRequestArgs(NIL,[20,0,'SwapName Plugin',body,gads],NIL,NIL)